import App from './App';
import store from './store';
//#ifdef H5
import jwx from '@/utils/jwx.js';
//#endif
// #ifndef VUE3
import Vue from 'vue';
import i18n from './i18n';

import uView from '@/uni_modules/uview-ui'
Vue.use(uView)

import mpShare from "@/uni_modules/uview-ui/libs/mixin/mpShare"
Vue.mixin(mpShare)

import category from '@/config/index.js'
const msg = (title, duration = 1500, mask = false, icon = 'none') => {
	//统一提示方便全局修改
	if (Boolean(title) === false) {
		return;
	}
	uni.showToast({
		title,
		duration,
		mask,
		icon
	});
}
const json = type => {
	//模拟异步请求数据
	return new Promise(resolve => {
		setTimeout(() => {
			resolve(Json[type]);
		}, 500)
	})
}

const deepClone = obj => {
	try {
		var str = JSON.stringify(obj)
		return JSON.parse(str)
	} catch (err) {
		return err
	}
}

const prePage = () => {
	let pages = getCurrentPages();
	let prePage = pages[pages.length - 2];

	// #ifdef H5
	return prePage;
	// #endif

	return prePage.$vm;
}


Vue.config.productionTip = false
Vue.prototype.$fire = new Vue();
Vue.prototype.$store = store;
Vue.prototype.$api = {
	msg,
	json,
	prePage,
	deepClone
};
Vue.prototype.$category = category
//#ifdef H5
Vue.prototype.$jwx = jwx
//#endif

App.mpType = 'app'
const app = new Vue({
	...App,
	store,
	i18n
})
app.$mount()

// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
export function createApp() {
	const app = createSSRApp(App)
	return {
		app
	}
}
// #endif